package friend

import (
	"api/pb/friend"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type PostFriendToGroupLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPostFriendToGroupLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PostFriendToGroupLogic {
	return &PostFriendToGroupLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// PostFriendToGroup 更新分组中的好友信息
func (l *PostFriendToGroupLogic) PostFriendToGroup(req *types.RelationToGroupInfo) (resp *types.Empty, err error) {
	// 可以批量拉入分组, 也可以批量从分组中删除
	_, err = l.svcCtx.FriendRPC.UpdateGroupRelation(l.ctx, &friend.RelationToGroup{
		GroupId:  req.GroupID,
		FriendId: req.FriendIDs,
		Status:   req.Status,
	})
	if err != nil {
		return nil, err
	}
	return &types.Empty{}, nil
}
